package com.xyzh.stj.web.service.impl;

import com.xyzh.stj.web.entity.UserRoleEntity;
import com.xyzh.stj.web.dao.UserRoleMapper;
import com.xyzh.stj.web.service.UserRoleService;
import com.xyzh.application.base.service.BasicServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 用户角色 服务实现类
 * </p>
 *
 * @author @JZB
 * @since 2023-10-29
 */
@Service
public class UserRoleServiceImpl extends BasicServiceImpl<UserRoleMapper, UserRoleEntity> implements UserRoleService {

    @Override
   public int addUserRoles(String userId, List<String> roles){

        UserRoleEntity deleteUserRole=new UserRoleEntity();
        deleteUserRole.setUserId(userId);
        this.deleteEntityNotId(deleteUserRole);

        int count=0;
        for(String role :roles){
            UserRoleEntity userRoleEntity=new UserRoleEntity();
            userRoleEntity.setRoleId(role);
            userRoleEntity.setUserId(userId);
            boolean res=this.saveEntity(userRoleEntity);
            if(res){
                count++;
            }
        }
        return count;
    }
    @Override
    public boolean deleteEntity(UserRoleEntity entity) {
        return super.deleteEntityNotId(entity);
    }
}
